package com.jed.xxh.adapter;

import android.content.Context;
import android.media.Image;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import com.jed.xxh.R;
import com.jed.xxh.entity.PhotoData;
import com.jed.xxh.utils.PicassoUtil;

import java.util.List;

/**
 * 项目名：SmartButler<br/>
 * 包名：  com.jed.xxh.adapter<br/>
 * 作者：徐晓辉<br/>
 * 创建日期：2018/11/30 12:49<br/>
 * 描述：图片Adapter<br/>
 */

public class PhotoAdapter extends MyBaseAdapter {

    private List<PhotoData> mList;
    private PhotoData mPhotoData;
    private WindowManager wm;
    private int width;

    public PhotoAdapter(List<PhotoData> mList) {
        super(mList);
        this.mList = mList;
        wm= (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        width = wm.getDefaultDisplay().getWidth();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = inflater.inflate(R.layout.photo_item, null);
            holder.imageView = view.findViewById(R.id.mImageView);
            view.setTag(holder);
        }else{
            holder = (Holder) view.getTag();
        }
        mPhotoData = mList.get(i);
        PicassoUtil.loadImgViewSize(mPhotoData.getUrl(),width/2,250,holder.imageView);
        return view;
    }

    class Holder {
        private ImageView imageView;
    }
}
